package code.rocky.sync;

import java.util.concurrent.TimeUnit;

public class SyncTest4 {

    private static int INIT_VALUE = 0;
    private static int TOTAL      = 10;

    static class count implements Runnable{
        @Override
        public void run() {
            while (true) {
                synchronized (SyncTest4.class) {
                    if (INIT_VALUE > TOTAL) {
                        break;
                    }
                    try {
                        TimeUnit.SECONDS.sleep(1);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + " INIT_VALUE: " + (INIT_VALUE++));
                }
            }
        }
    }

    public static void main(String[] args) {

        new Thread(new SyncTest4.count(),"t1").start();
        new Thread(new SyncTest4.count(),"t2").start();
        new Thread(new SyncTest4.count(),"t3").start();

    }


}


